// pages/createroom/createroom.js
const db = wx.cloud.database();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    colorList:[
      "111", 
      "#BB6A54", "#E1BEBE",
      "#BB6A54", "#DCC896",
      "#E2C9F1","#CFD66E",
      "#5594C7","#D3D3D1",
      "#B9696A",
      "#83A569","#9899B7",
      "#DDAE7A","#775D79"
    ],
    imgurlList:[
      "",
      "https://z3.ax1x.com/2021/04/30/gEQ45q.png",
      "https://z3.ax1x.com/2021/04/30/gEQhan.png",
      "https://z3.ax1x.com/2021/04/30/gEQfVs.png",
      "https://z3.ax1x.com/2021/04/26/gpQvvt.png",
      "https://z3.ax1x.com/2021/04/26/gpQjgI.png",
      "https://z3.ax1x.com/2021/04/26/gpQX8A.png",
      "https://z3.ax1x.com/2021/04/26/gpQOCd.png",
      "https://z3.ax1x.com/2021/04/26/gpQbUe.png",
      "https://z3.ax1x.com/2021/04/26/gpQHED.png",
      "https://z3.ax1x.com/2021/04/26/gpQTHO.png",
      "https://z3.ax1x.com/2021/04/26/gpQoDK.png",
  ]
  },

btnSubmit(res){//提交表单
    var{roomname,maxnumber,introduction}=res.detail.value;
    var colorint = Math.ceil(Math.random()*11);//获取1-11之间的整数 
    wx.cloud.callFunction({
      name:"createstudyroom",
      data:{
        roomname:roomname,
        maxnumber:maxnumber,
        introduction:introduction,
        color: this.data.colorList[colorint],
        imgurl:this.data.imgurlList[colorint]
      }
    }).then(res=>{
      console.log(res)
      wx.switchTab({
        url: '../../pages/study/study',
      })
    })  

},

  cancelCreateroom(){
  wx.switchTab({
    url: '../../pages/study/study',
  })
  },

  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})